package com.raulraja.model.domain.impl;

import com.raulraja.model.domain.DomainObject;
import com.raulraja.model.domain.PersistentObject;
import com.raulraja.model.domain.readonly.PersonReadOnly;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
 * Entity that represents a person
 */
@Entity
@javax.persistence.SequenceGenerator(name="SEQ_Person",sequenceName="Person_sequence")
public class Person implements DomainObject, PersistentObject, PersonReadOnly {

	/**
	 * the person's unique identifier
	 */
	@Id
	@GeneratedValue(strategy=javax.persistence.GenerationType.SEQUENCE,generator="SEQ_Person")
	private Long id;

	/**
	 * the person's email
	 */
	private String email;

	/**
	 * the person's password
	 */
	private String password;


	/**
	 * whether this person is active on the system
	 */
	@Column(columnDefinition = "BOOLEAN default FALSE")
	private boolean active;


	/**
	 * @return the person's unique identifier
	 */
	public Long getId() {
		return id;
	}

	/**
	 * sets the id
	 * @param id the person's unique identifier
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the person's email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * sets the email
	 * @param email the person's email
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the person's password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * sets the password
	 * @param password the person's password
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return whether this person is active on the system
	 */
	public boolean isActive() {
		return active;
	}

	/**
	 * marks this person as active or not active
	 * @param active if the person is active
	 */
	public void setActive(boolean active) {
		this.active = active;
	}

	/**
	 * Equals implementation based on id
	 * @param o other object
	 * @return if the compared objects are equal
	 */
	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null || getClass() != o.getClass()) {
			return false;
		}

		Person person = (Person) o;

		if (id != null ? !id.equals(person.id) : person.id != null) {
			return false;
		}

		return true;
	}

	/**
	 * Hashcode impl based on id
	 * @return this persons id hashcode or 0 if the id is null
	 */
	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}
}
